package com.example.mallsystem1104.controller;

import com.example.mallsystem1104.annotation.Authority;
import com.example.mallsystem1104.common.Result;
import com.example.mallsystem1104.entity.AuthorityType;
import com.example.mallsystem1104.entity.Icon;
import com.example.mallsystem1104.service.IconService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author zy
 * @Date 2024/12/11 15:18
 * @packageName:com.example.mallsystem1104.controller
 * @ClassName:IconController
 */

@RestController
@RequestMapping("/api/icon")
@CrossOrigin
public class IconController {

    @Resource
    private IconService iconService;

    @GetMapping
    public Result findAll(){
        List<Icon> iconList=iconService.getIconCategoryMapList();
        return Result.success(iconList);
    }

    @GetMapping("/{id}")
    public Result findById(@PathVariable int id){
        return Result.success(iconService.getById(id));
    }

    @PostMapping
    @Authority(AuthorityType.requireAuthority)
    public Result save(@RequestBody Icon icon){
        iconService.saveOrUpdate(icon);
        return Result.success();
    }

    @PutMapping
    @Authority(AuthorityType.requireAuthority)
    public Result update(@RequestBody Icon icon){
        iconService.updateById(icon);
        return Result.success();
    }

    @DeleteMapping
    @Authority(AuthorityType.requireAuthority)
    public Result deleteBuId(@PathVariable int id){
        return Result.success(iconService.getBaseMapper().deleteById(id));
    }

}
